package cn.itcast.item.config;

import cn.itcast.hmall.constants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//声明队列和交换机
@Configuration
public class MqConfig {
    /**
     * 交换机
     *
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(MqConstants.ITEM_EXCHANGE);
    }

    /**
     * 新增和修改
     *
     * @return
     */
    @Bean
    public Queue insertQueue() {
        return new Queue(MqConstants.ITEM_INSERT_QUEUE);
    }

    /**
     * 删除
     *
     * @return
     */
    @Bean
    public Queue deleteQueue() {
        return new Queue(MqConstants.ITEM_DELETE_QUEUE);
    }

    /**
     * 上架
     *
     * @return
     */
    @Bean
    public Queue upQueue() {
        return new Queue(MqConstants.ITEM_UP_QUEUE);
    }

    /**
     * 下架
     *
     * @return
     */
    @Bean
    public Queue downQueue() {
        return new Queue(MqConstants.ITEM_DOWN_QUEUE);
    }

    /**
     * 新增和修改RoutingKey
     *
     * @return
     */
    @Bean
    public Binding insertQueueBinding() {
        return BindingBuilder.bind(insertQueue()).to(topicExchange()).with(MqConstants.ITEM_INSERT_KEY);
    }

    /**
     * 删除RoutingKey
     *
     * @return
     */
    @Bean
    public Binding deleteQueueBinding() {
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstants.ITEM_DELETE_KEY);
    }

    /**
     * 上架RoutingKey
     *
     * @return
     */
    @Bean
    public Binding upQueueBinding() {
        return BindingBuilder.bind(upQueue()).to(topicExchange()).with(MqConstants.ITEM_UP_KEY);
    }

    /**
     * 下架RoutingKey
     *
     * @return
     */
    @Bean
    public Binding downQueueBinding() {
        return BindingBuilder.bind(downQueue()).to(topicExchange()).with(MqConstants.ITEM_DOWN_KEY);
    }
}
